home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / doGhost.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.3 KB  |  307 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  Sept, 2000
  22. //  Author:         bb
  23. //
  24. //    Procedure Name:
  25. //        doGhost
  26. //
  27. //    Description:
  28. //        Enable or disable ghosting on the selected objects.
  29. //
  30. //    Input Arguments:
  31. //    $version: The version of this option box.  Used to know how to 
  32. //    interpret the $args array.
  33. //        "1" : first version of ghosts
  34. //        "2" : second version of ghosts
  35. //  
  36. //    $args
  37. //    Version 1
  38. //    [0]        $enable: enable or disable ghosts
  39. //    Version 2
  40. //    [0]        $enable: enable or disable ghosts
  41. //    [1]        $ghostControl: ghostControl attribute value for ghosted objects
  42. //    [2]        $pre: ghostPreSteps attribute value for ghosted objects
  43. //    [3]        $post: ghostPostSteps attribute value for ghosted objects
  44. //    [4]        $stepSize: ghostFramesPerStep attribute value for ghosted objects
  45. //    [5]        $frames: ghostFrames attribute value for ghosted objects
  46. //    [6]        $start: ghostRangeStart attribute value for ghosted objects
  47. //    [7]        $end: ghostRangeEnd attribute value for ghosted objects
  48. //    [8]        $ghostDriver: the driver object whose keys are to ghost $obj
  49. //
  50. //    Return Value:
  51. //        none
  52. //
  53.  
  54. proc string buildGhostSetAttrString(string $obj,
  55.                                     int $enable,
  56.                                     int $ghostControl,
  57.                                     int $pre,
  58.                                     int $post,
  59.                                     int $stepSize,
  60.                                     string $frames,
  61.                                     float $start,
  62.                                     float $end,
  63.                                     string $ghostDriver)
  64. //
  65. // Description: Based on the argument values, build up a setAttr
  66. //  command to control the specified ghosting attributes of the object.
  67. //   $object: object to act on
  68. //   $enable: enable or disable ghosting    
  69. //     $ghostControl: ghostControl attribute value for ghosted objects
  70. //     Possible values are: 
  71. //           0: global preferences
  72. //           1: custom frames
  73. //           2: custom frame pre/post
  74. //           3: custom key pre/post
  75. //           4: keyframe range
  76. //          -1: do not modify ghost control or its associated attributes,
  77. //              leave them as they are    
  78. //     $pre: ghostPreSteps attribute value for ghosted objects
  79. //     $post: ghostPostSteps attribute value for ghosted objects
  80. //     $stepSize: ghostFramesPerStep attribute value for ghosted objects
  81. //     $frames: ghostFrames attribute value for ghosted objects
  82. //     $start: ghostRangeStart attribute value for ghosted objects
  83. //     $end: ghostRangeEnd attribute value for ghosted objects
  84. //     $ghostDriver: the driver object whose keys are to ghost $obj
  85. //
  86. {
  87.     string $setAttrCmds = ("setAttr "+$obj+".ghosting "+$enable+"; ");
  88.     // Break the connection to ghostDriver attr
  89.     string $srcAttrs[] = `listConnections -s true -d false -p true ($obj+".ghostDriver")`;
  90.     if (size($srcAttrs) > 0) {
  91.         $setAttrCmds += ("disconnectAttr " + $srcAttrs[0] + " " + $obj + ".ghostDriver; ");
  92.     }
  93.  
  94.     if (0 == $enable || (-1 == $ghostControl)) {
  95.         // the other ghosting attrs do not matter if we are not ghosting,
  96.         // so return the command string now
  97.         //
  98.         return $setAttrCmds;
  99.     }
  100.  
  101.     // type of ghosting control
  102.     //
  103.     $setAttrCmds += ("setAttr "+$obj+".ghostingControl "+$ghostControl+"; ");
  104.  
  105.     switch ($ghostControl) {
  106.     case 0:
  107.     {
  108.         // global preferences, nothing to do here
  109.     }    break;
  110.     case 1: {
  111.         // custom frames
  112.         $setAttrCmds += ("setAttr "+$obj+".ghostFrames -typ Int32Array ");
  113.         $setAttrCmds += ($frames+"; ");
  114.     }    break;
  115.     case 2: 
  116.     case 3: {
  117.         // custom pre, post
  118.         $setAttrCmds += ("setAttr "+$obj+".ghostPreSteps "+$pre+"; ");
  119.         $setAttrCmds += ("setAttr "+$obj+".ghostPostSteps "+$post+"; ");
  120.         $setAttrCmds += ("setAttr "+$obj+".ghostStepSize "+$stepSize+"; ");
  121.     }    break;
  122.     case 4: {
  123.         // keyframes
  124.         $setAttrCmds += ("setAttr "+$obj+".ghostRangeStart "+$start+"; ");
  125.         $setAttrCmds += ("setAttr "+$obj+".ghostRangeEnd "+$end+"; ");
  126.     }    break;
  127.     }
  128.  
  129.     if ($ghostDriver != "")
  130.         $setAttrCmds += ("connectAttr -f " + $ghostDriver + " " + $obj + ".ghostDriver");
  131.  
  132.     return $setAttrCmds;
  133. }
  134.  
  135. proc int isTransform(string $obj) 
  136. {
  137.     string $isTransform[] = `ls -type transform $obj`;
  138.     return size($isTransform);
  139. }
  140.  
  141. proc int isJoint(string $obj)
  142. {
  143.     string $type = `nodeType $obj`;
  144.     return $type == "joint";
  145. }
  146.  
  147. proc int isIntermediateObject(string $obj)
  148. {
  149.     int $val = `getAttr ($obj+".intermediateObject")`;
  150.     return $val == 1;
  151. }
  152.  
  153. proc int ghostIt(string $object, int $enable,
  154.                  int $ghostControl,
  155.                  int $pre,
  156.                  int $post,
  157.                  int $stepSize,
  158.                  string $frames,
  159.                  float $start,
  160.                  float $end,
  161.                  int $hier,
  162.                  string $ghostDriver)
  163. //
  164. // Description: ghost or unghost an object
  165. // Args: 
  166. //   $object: object to act on
  167. //   $enable: whether or not to ghost
  168. //     $ghostControl: ghostControl attribute value for ghosted objects
  169. //     $pre: ghostPreSteps attribute value for ghosted objects
  170. //     $post: ghostPostSteps attribute value for ghosted objects
  171. //     $stepSize: ghostStepSize attribute value for ghosted objects
  172. //     $frames: ghostFrames attribute value for ghosted objects
  173. //     $start: ghostRangeStart attribute value for ghosted objects
  174. //     $end: ghostRangeEnd attribute value for ghosted objects
  175. //     $hierarchy: whether to ghost the hierarchy below the selected object
  176. //     $ghostDriver: the driver object whose keys are to ghost $object
  177. //
  178. {
  179.     int $setGhost = 0;
  180.     string $rels[];
  181.     if($hier) {
  182.         // include all the descedents
  183.         $rels = `listRelatives -pa -ad $object`;
  184.     } else {
  185.         // Ghost children if $object is a transform
  186.         if (isTransform($object) && !isJoint($object)) {
  187.             $rels = `listRelatives -pa $object`;
  188.         }
  189.     }
  190.     // include itself at the end of $rels[]
  191.     $rels[size($rels)] = $object;
  192.  
  193.     for($rel in $rels) {
  194.         // Ghost a node only if it's not a transform or if it's a joint
  195.         if (!isTransform($rel) || isJoint($rel)) {
  196.             if (!isIntermediateObject($rel)) {
  197.                 string $cmd = buildGhostSetAttrString(
  198.                         $rel, $enable, $ghostControl,
  199.                         $pre,$post,$stepSize,
  200.                         $frames, $start,$end,$ghostDriver);
  201.                 evalEcho $cmd;
  202.                 $setGhost += 1;
  203.             }
  204.         }
  205.     }
  206.     return $setGhost;
  207. }
  208.  
  209. global proc
  210. doGhost( string $version, string $args[] )
  211. //
  212. // Description:
  213. //   This procedure is used to enable or disable ghosts.
  214. //   The arguments are implemented using a string array to
  215. //     allow a variable number of arguments depending on the
  216. //   version.
  217. // Arguments:
  218. //    $version: the version    
  219. //      $args
  220. //      Version 2
  221. //       [0]        $enable: enable or disable ghosts
  222. //       [1]        $hierarchy: whether to ghost the hierarchy below the selected object
  223. //       [2]        $ghostControl: ghostControl attribute value for ghosted objects
  224. //       [3]        $pre: ghostPreSteps attribute value for ghosted objects
  225. //       [4]        $post: ghostPostSteps attribute value for ghosted objects
  226. //       [5]        $stepSize: ghostStepSize attribute value for ghosted objects
  227. //       [6]        $frames: ghostFrames attribute value for ghosted objects
  228. //       [7]        $start: ghostRangeStart attribute value for ghosted objects
  229. //       [8]        $end: ghostRangeEnd attribute value for ghosted objects
  230. //       [9]        $useGhostDriver: whether to use first object's keys to ghost the rest objects
  231. //
  232. {
  233.     int $counter = 0;
  234.     int $enable = $args[0];
  235.     int $ghostControl = -1; // leave ghost control as is
  236.     int $pre = 0;
  237.     int $post = 0;
  238.     int $stepSize = 0;
  239.     string $frames;
  240.     float $start = 0;
  241.     float $end = 0;
  242.     int $hier = 0;
  243.     int $useGhostDriver = 0;
  244.     string $selection[] = `ls -sl`;
  245.  
  246.     int $versionNo = $version;
  247.     if ($versionNo > 1) {
  248.         $hier = $args[1];
  249.         $ghostControl = $args[2];
  250.         $pre = $args[3];
  251.         $post = $args[4];
  252.         $stepSize = $args[5];
  253.         $frames = $args[6];
  254.         $start = $args[7];
  255.         $end = $args[8];
  256.         $useGhostDriver = $args[9];
  257.     }
  258.  
  259.     if ($useGhostDriver) {
  260.         if ($enable) {
  261.             if (size($selection) < 2) {
  262.                 error("Use Ghost Driver is on. Select a driver object, then driven objects.");
  263.                 return;
  264.             }
  265.         } else {
  266.             if (size($selection) == 0) {
  267.                 error("Select objects to be unghosted.");
  268.                 return;
  269.             }
  270.         }
  271.     } else {
  272.         if (size($selection) == 0) {
  273.             if ($enable) {
  274.                 error("Select objects to be ghosted.");
  275.             } else {
  276.                 error("Select objects to be unghosted.");
  277.             }
  278.             return;
  279.         }
  280.     }
  281.  
  282.     int    $i = 0;
  283.     string $ghostDriver;
  284.     if ($useGhostDriver && $enable) {
  285.         $ghostDriver = $selection[0] + ".message";
  286.         $i = 1;
  287.     }
  288.  
  289.     int $numObj = `size $selection`;
  290.     for( ; $i < $numObj; $i++) {
  291.         string $sel = $selection[$i];
  292.         $counter += ghostIt(    $sel,
  293.                     $enable,
  294.                     $ghostControl,
  295.                     $pre,$post,$stepSize,
  296.                     $frames,
  297.                     $start,
  298.                     $end,
  299.                     $hier,
  300.                     $ghostDriver);
  301.     }
  302.  
  303.     if ($counter == 0 && $enable) {
  304.         error("Objects selected could not be ghosted.");
  305.     }
  306. }
  307.